function[]=zadani(akce)
%ZADANI  calls up a window for editting smoothing parameters
%
%     Use only in procedure KERN
%
% (C) Jan Kolacek, Masaryk University (Czech Republic)

if nargin<1
 akce='inic';
end;
echo off;
if strcmp(akce,'inic')
   n=0;k=2;m=1;h=0.1;
   save v h -append;
   
figNumber=figure(...
	'Visible','off', ...
   'Units','normalized',...
   'Name','EDIT', ...
   'Color',[.3 .3 .3],...
   'Tag','kclos',...
   'NumberTitle','off');

save v figNumber -append;
% First, the MiniCommand Window frame
    
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.03,0.89,.3,.08], ...
        'BackgroundColor',[0.50 0.50 0.50]);
%pause;
% Then the text label
    
    uicontrol( ...
	    'Style','text', ...
        'HorizontalAlignment','left',...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.05,.9,.08,.05], ...
        'BackgroundColor',[0.50 0.50 0.50], ...
        'ForegroundColor',[1 1 1], ...
        'String','Set nu');

% Generic popup button information
    nHndl=uicontrol( ...
        'Style','popup', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.15,.915,.16,.04], ...
        'String',num2str((0:20)'), ...
        'Callback','zadani(''prac'');');


% First, the MiniCommand Window frame
    
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.03,0.79,.3,.08], ...
        'BackgroundColor',[0.50 0.50 0.50]);
%pause;
% Then the text label
    
uicontrol( ...
      	'Style','text', ...
      'Units','normalized', ...
      'HorizontalAlignment','left',...
      'FontUnits','normalized',...
      'Position',[.05,.8,.08,.05], ...
      'BackgroundColor',[0.50 0.50 0.50], ...
      'ForegroundColor',[1 1 1], ...
      'String','Set k');
% Generic popup button information
kHndl=uicontrol( ...
        'Style','popup', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.15,.815,.16,.04], ...
        'String',num2str((2:22)'), ...
        'Callback','zadani(''prac'');');

% First, the MiniCommand Window frame
    
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.03,0.69,.3,.08], ...
	     'BackgroundColor',[0.50 0.50 0.50]);
%pause;
% Then the text label
    
    uicontrol( ...
	     'Style','text', ...
        'HorizontalAlignment','left',...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.05,.7,.08,.05], ...
        'BackgroundColor',[0.50 0.50 0.50], ...
	     'ForegroundColor',[1 1 1], ...
        'String','Set mu');
% Generic popup button information
    mHndl=uicontrol( ...
	     'Style','popup', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.15,.715,.16,.04], ...
        'String',num2str((-1:20)'), ...
        'Callback','zadani(''prac'');');


% First, the MiniCommand Window frame
    
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.03,0.59,.3,.08], ...
	     'BackgroundColor',[0.50 0.50 0.50]);
%pause;
% Then the text label
    
    uicontrol( ...
	     'Style','text', ...
        'HorizontalAlignment','left',...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.05,.6,.08,.05], ...
        'BackgroundColor',[0.50 0.50 0.50], ...
	     'ForegroundColor',[1 1 1], ...
        'String','Set h');
%pause;
% Then the editable text field
    hHndl=uicontrol( ...
	     'Style','edit', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Max',1, ...
        'Min',1, ...
        'BackgroundColor',[.9 .9 .9], ...
 	     'Callback','zadani(''prac'')' , ...
        'Position',[.15,.61,.16,.045], ...
        'String','0',...%%%%
        'HorizontalAlignment','left'); 

% Then the text label
    
   evHndl = uicontrol( ...
	     'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.03,0.52,.3,.06], ...
        'BackgroundColor',[0.30 0.30 0.30], ...
	    'ForegroundColor',[0.6 0.2 0.2], ...
        'String','The sum nu+k should be even!');
set(evHndl,'Visible','off');

% Then the text label
    
   inqHndl = uicontrol( ...
	     'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.03,0.52,.3,.06], ...
        'BackgroundColor',[0.30 0.30 0.30], ...
	    'ForegroundColor',[0.6 0.2 0.2], ...
        'String','The inequality nu < k should be satisfied!');
set(inqHndl,'Visible','off');

%hlpstr=['Nejprve je treba zvolit rad a hladkost jadra, ktere' 
%        'se pouzije pri vyhlazovani.                        '
%        'Jadro bude radu (n,k), pricemz n+k by melo byt     '
%        'sude. Bude hladkosti m, tj. bude mit spojite m-te  ' 
%        'derivace. Pokud se zada m = 0, pouzije se pro vy-  '
%        'hlazeni jadro s minimalnim rozptylem.              '
%        'Dale je treba zvolit sirka okna h.                 '];
% hlpstr=['Firstly set the order and the smoothness of the ker-'
%         'nel, which will be used for kernel estimation.      '
%         'The kernel will be of order (n,k), where n+k should '
%         'be even. For an estimation of a regression function ' 
%         'use n = 0. The parameter m is the smoothness of this' 
%         'kernel.                                             '
%         'Finally set the bandwidth h. The value should be    '
%         'between 0 and 1.                                    '];
hlpstr=['Firstly set the order and the smoothness of the kernel, ',...
        'which will be used for kernel estimation. The kernel will be ',...
        'of order (nu,k), nu < k, nu+k should be even. For an estimation ',... 
        'of a regression function use nu = 0. The parameter mu is the ',...
        'smoothness of this kernel, mu=-1 is for non-continuous kernel.',... 
        'Finally set the bandwidth h. The value should be between 0 and 1.'];
    
% Then the editable text field
    eHndl=uicontrol( ...
	     'Style','text', ...
        'Units','normalized', ...
        'Max',10, ...
        'BackgroundColor',[.9 .9 .9], ...
        'Position',[.38,.33,.55,.64], ...
        'FontSize',10, ...
        'FontUnits','normalized',...
        'HorizontalAlignment','left', ...nada
        'String',hlpstr);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     uicontrol('Style','push','Units','normalized', ...
          'FontUnits','normalized',...
          'Position',[.63,.05,.14,.08], ...
          'Callback','zadani(''prac'');load v;okop;', ...
          'BackgroundColor',[.5,0.5,0.5], ...
          'String','"Eye" method');

     uicontrol('Style','push','Units','normalized', ...
          'FontUnits','normalized',...
          'Position',[.79,.15,.14,.08], ...
          'Callback','zadani(''prac'');load v.mat n k m;drkern(n,k,m)', ...
          'BackgroundColor',[.5,0.5,0.5], ...
          'String','Draw the kern');
       
       uicontrol('Style','push','Units','normalized', ...
          'FontUnits','normalized',...
          'Position',[.63,.15,.14,.08], ...
          'Callback',['zadani(''prac'');',...
          'kfig=findobj(0,''name'',''KERNEL SMOOTHING'');set(kfig,''Visible'',''off'');', ...
          'set(kfig,''Visible'',''on'');'], ...
          'BackgroundColor',[.5,0.5,0.5], ...
          'String','OK');
       
       closeStr=['set(gcf,''CloseRequestFcn'',''closereq'');',...
             'delete(findobj(0,''Tag'',''eclos''));delete(gcf);'];
       uicontrol('Style','push','Units','normalized', ...
          'FontUnits','normalized',...
          'Position',[.79,.05,.14,.08], ...
          'Callback',closeStr, ...
          'BackgroundColor',[.5,0.5,0.5], ...
          'String','Close');
       
set(gcf,'CloseRequestFcn',closeStr);
     
 algHndl=uicontrol('Style','push','Units','normalized', ...
    'Position',[.03,.41,.3,.1], ...
    'Callback',['alg(''start'');'],...
    'BackgroundColor',[.5,0.5,0.5], ...
    'FontUnits','normalized',...
    'String','Algorithm for optimal parameters');
 
        
     % First, the MiniCommand Window frame
    
uicontrol( ...
     'Style','frame', ...
     'Units','normalized', ...
     'FontUnits','normalized',...
     'Position',[.03,0.05,.55,.22]);
  
menuHndl=uicontrol('Style','push','Units','normalized', ...
    'FontUnits','normalized',...
    'Position',[.35,.07,.1,.07], ...
    'Callback','hledani;',...
    'Enable','off',...
    'BackgroundColor',[.5,0.5,0.5], ...    
    'String','Menu');
%infstr=['Vyberte typ vyhlazovace. Tlacitko "Menu" zobrazi nabidku'
%        'na hledani optimalni sirky okna.                        '];     
infstr='Choose the type of the estimator. The button "Menu" shows the window for estimating of optimal h.';     
% Then the editable text field
uicontrol( ...
	'Style','text', ...
        'Units','normalized', ...
        'Position',[.26,.15,.3,.1], ...
        'HorizontalAlignment','left',...
        'FontSize',8, ...
        'FontUnits','normalized',...
        'String',infstr);
     
c1='hL=get(gcf,''UserData'');set(hL(9),''enable'',''on'');';     
c2='set(hL(6:8),''value'',0);set(hL(5),''value'',1)';
nwHndl=uicontrol('Style','radiobutton','Units','normalized', ...
    'FontUnits','normalized',...
    'Position',[.04,.21,.2,.05], ...
    'Callback',[c1,c2],...
    'String','Nadaraya - Watson');
 
c2='set(hL([5,7,8]),''value'',0);set(hL(6),''value'',1)';
llHndl=uicontrol('Style','radiobutton','Units','normalized', ...
    'FontUnits','normalized',...
    'Position',[.04,.16,.2,.05], ...
    'Callback',[c1,c2],...
    'String','Local - linear');

c2='set(hL([5,6,8]),''value'',0);set(hL(7),''value'',1)';
gmHndl=uicontrol('Style','radiobutton','Units','normalized', ...
    'FontUnits','normalized',...
    'Position',[.04,.11,.2,.05], ...
    'Callback',[c1,c2],...
    'String','Gasser - Mueller');
 
c2='set(hL(5:7),''value'',0);set(hL(8),''value'',1)';
pchHndl=uicontrol('Style','radiobutton','Units','normalized', ...
    'FontUnits','normalized',...
    'Position',[.04,.06,.2,.05], ...
    'Callback',[c1,c2],...
    'String','Priestley - Chao');
 
 %zavnw zavll zavgm zavnw1 zavll1 zavgm1        
 hndlList=[nHndl kHndl mHndl hHndl nwHndl llHndl gmHndl,...
       pchHndl menuHndl algHndl eHndl evHndl inqHndl];
set(figNumber,'Visible','on', ...
       'UserData',hndlList);

set(nHndl,'Value',1);set(kHndl,'Value',1);
set(mHndl,'Value',2);set(hHndl,'String','0.1');
%set(gcf,'Position',[0 0.0347 1.0000 0.9190]);
set(gcf,'Position',[0.1059 0.1655 0.7700 0.6898]);

zadani('prac');

elseif strcmp(akce,'prac')
thisFig=findobj(0,'name','EDIT');
hndlList=get(thisFig,'UserData');   
nHndl=hndlList(1);
kHndl=hndlList(2);
mHndl=hndlList(3);
hHndl=hndlList(4);
evHndl=hndlList(12);
inqHndl=hndlList(13);
n=get(nHndl,'Value')-1;
k=get(kHndl,'Value')+1;
m=get(mHndl,'Value')-1;
h=get(hHndl,'String');
h=str2num(h);
l=length(h);
if l>1
   h=h(l);
end;
ev = n + k;
if round(ev/2)~=(ev/2)
    set(evHndl,'Visible','on');
else
    set(evHndl,'Visible','off');
end

if n>=k
    set(inqHndl,'Visible','on');
else
    set(inqHndl,'Visible','off');
end
save v.mat n k m h -append;
end;



